package com.hotec.PROJECT_NAME.modules.sys.mapper;

import com.hotec.PROJECT_NAME.modules.sys.entity.SysRole;
import com.hotec.PROJECT_NAME.component.basic.BasicMapper;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;


/**
 * @author llb
 */
public interface SysRoleMapper extends BasicMapper<SysRole> {
    /**
     * 根据用户ID，查询用户角色
     *
     * @param accountId
     * @return
     */
    @SelectProvider(type = RoleProvider.class, method = "getRoleByAccountId")
    List<SysRole> getRoleByAccountId(String accountId);

    class RoleProvider {
        public String getRoleByAccountId(String accountId) {
            StringBuilder sb = new StringBuilder("select DISTINCT role.* from sys_role_account roleLogin,sys_role role " +
                    "WHERE roleLogin.account_id=#{accountId}  AND roleLogin.role_id = role.id AND role.del_flag='0' AND roleLogin.del_flag='0' AND role.state='1' AND roleLogin.state='1'");
            return sb.toString();
        }
    }
}

